package cn.bookcycle.panda.user.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

//import org.apache.commons.httpclient.HttpClient;


public class DBUtil {
	
	public static String sendPost(String uri, String paramName,String param, String charset) {  
        String result = "";  
        PrintWriter out =null;  
        InputStream in = null;  
        try {  
            //URL url = new URL(URLEncoder.encode(uri, "iso-8859-1")); 
        	URL url=new URL(uri);
            //URL url=URLEncoder.encode(uri, charset);
            
            HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();  
            urlcon.setDoInput(true);  
            urlcon.setDoOutput(true);  
            urlcon.setUseCaches(false);  
            urlcon.setRequestMethod("POST");
            //urlcon.setRequestProperty("contentType", "utf-8");
            
            urlcon.connect();// ��ȡ����  
            out = new PrintWriter(urlcon.getOutputStream());  
           
            param = URLEncoder.encode(param, "utf-8");
            out.print(paramName+"="+param);  
            out.flush();  
            in = urlcon.getInputStream();  
            BufferedReader buffer = new BufferedReader(new InputStreamReader(  
                    in, charset));  
            StringBuffer bs = new StringBuffer();  
            String line ="" ;  
            while ((line = buffer.readLine()) !=null ) {  
                bs.append(line);  
            }  
            result = bs.toString();  
        } catch (Exception e) {  
            e.printStackTrace();
        } finally {
            try {
                if ( null != in)  
                    in.close();  
                if ( null != out)  
                    out.close();  
            } catch (Exception e2) {  
              e2.printStackTrace();
            }  
        }
        if("\"no results\"".equals(result)){
            return null;
        }else {
            return result;
        }

    }  
}  

